//
// Created by ✎﹏ℳ๓独赏 ☆独醉 on 2023/4/19.
//
#include <stdio.h>
#define N 10
void dublebubble(int a[], int n)
{
    int i, j ,temp1,temp2;
    while (n/2 > 1)//单向冒泡要冒n-1趟，双向只要冒n/2-1趟
    {
        for (i = 0; i < n - 1; i++)
        {
            if (a[i] > a[i + 1])
            {
                temp1 = a[i];
                a[i] = a[i + 1];
                a[i + 1] = temp1;
            }
        }
        //一趟从左向右冒泡结束
        n--;//最大数已经在最右侧，j从倒数第二个数开始
        for (j = n - 1; j >= 0; j--)
        {
            if (a[j] < a[j - 1])
            {
                temp2 = a[j];
                a[j] = a[j - 1];
                a[j - 1] = temp2;
            }
        }//一趟从右向左冒泡结束
    }
}
int main()
{
    int a[N]={9,8,7,6,5,4,3,2,1,0},i;
    dublebubble(a, N);
    for(i=0;i<N;i++){
        printf("%d ",a[i]);
    }
    return 0;
}

